Conditions | 1 |
Paths | 1 |
Total Lines | 588 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
9 | describe('Root', function(){ |
||
10 | |||
11 | var fullJSON = { |
||
12 | id: 'gedcomx', |
||
13 | lang: 'en', |
||
14 | description: '#sd1', |
||
15 | attribution: { |
||
16 | changeMessage: 'It changed', |
||
17 | contributor: { resource: 'https://myapp.com/contributor'}, |
||
18 | created: 1111338494969, |
||
19 | creator: { resource: 'https://myapp.com/creator'}, |
||
20 | modified: 1111338494969 |
||
21 | }, |
||
22 | persons: [ |
||
23 | { |
||
24 | private: false, |
||
25 | gender: { |
||
26 | type: 'http://gedcomx.org/Female' |
||
27 | }, |
||
28 | names: [ |
||
29 | { |
||
30 | type: 'http://gedcomx.org/BirthName', |
||
31 | nameForms: [ |
||
32 | { |
||
33 | fullText: 'Joanna Hopkins' |
||
34 | } |
||
35 | ] |
||
36 | } |
||
37 | ], |
||
38 | facts: [ |
||
39 | { |
||
40 | type: 'http://gedcomx.org/Birth', |
||
41 | date: { |
||
42 | formal: '+2001-04-09' |
||
43 | }, |
||
44 | place: { |
||
45 | original: 'Farm house' |
||
46 | } |
||
47 | } |
||
48 | ] |
||
49 | } |
||
50 | ], |
||
51 | relationships: [ |
||
52 | { |
||
53 | type: 'http://gedcomx.org/Couple', |
||
54 | person1: { |
||
55 | resource: 'http://identifier/for/person/1' |
||
56 | }, |
||
57 | person2: { |
||
58 | resource: 'http://identifier/for/person/2' |
||
59 | }, |
||
60 | facts: [ |
||
61 | { |
||
62 | type: 'http://gedcomx.org/Marriage' |
||
63 | } |
||
64 | ] |
||
65 | } |
||
66 | ], |
||
67 | sourceDescriptions: [ |
||
68 | { |
||
69 | id: 'sd1', |
||
70 | resourceType: 'http://some/type', |
||
71 | citations: [ |
||
72 | { |
||
73 | lang: 'en', |
||
74 | value: 'Long source citation' |
||
75 | } |
||
76 | ], |
||
77 | mediaType: 'book', |
||
78 | about: 'http://a/resource', |
||
79 | mediator: { |
||
80 | resource: 'http://mediator' |
||
81 | }, |
||
82 | sources: [ |
||
83 | { |
||
84 | description: 'http://source/reference' |
||
85 | } |
||
86 | ], |
||
87 | analysis: { |
||
88 | resource: 'http://analysis' |
||
89 | }, |
||
90 | componentOf: { |
||
91 | description: 'http://container' |
||
92 | }, |
||
93 | titles: [ |
||
94 | { |
||
95 | lang: 'en', |
||
96 | value: 'Title' |
||
97 | }, |
||
98 | { |
||
99 | lang: 'es', |
||
100 | value: 'Titulo' |
||
101 | } |
||
102 | ], |
||
103 | notes: [ |
||
104 | { |
||
105 | subject: 'Note', |
||
106 | text: 'Some note text' |
||
107 | } |
||
108 | ], |
||
109 | attribution: { |
||
110 | created: 1234578129 |
||
111 | }, |
||
112 | rights: [ |
||
113 | { |
||
114 | resource: 'https://some/right' |
||
115 | } |
||
116 | ], |
||
117 | coverage: { |
||
118 | temporal: { |
||
119 | formal: '+2015' |
||
120 | }, |
||
121 | spatial: { |
||
122 | original: 'A place' |
||
123 | } |
||
124 | }, |
||
125 | descriptions: [ |
||
126 | { |
||
127 | value: 'A description' |
||
128 | } |
||
129 | ], |
||
130 | identifiers: { |
||
131 | $: 'identifier' |
||
132 | }, |
||
133 | created: 1000000, |
||
134 | modified: 11111111, |
||
135 | repository: { |
||
136 | resource: 'http://repository' |
||
137 | } |
||
138 | } |
||
139 | ], |
||
140 | agents: [ |
||
141 | { |
||
142 | id: 'agent', |
||
143 | identifiers: { |
||
144 | $: 'ident' |
||
145 | }, |
||
146 | names: [ |
||
147 | { |
||
148 | lang: 'en', |
||
149 | value: 'Name' |
||
150 | } |
||
151 | ], |
||
152 | homepage: { |
||
153 | resource: 'http://homepage' |
||
154 | }, |
||
155 | openid: { |
||
156 | resource: 'http://openid' |
||
157 | }, |
||
158 | accounts: [ |
||
159 | { |
||
160 | accountName: 'jimbo' |
||
161 | } |
||
162 | ], |
||
163 | emails: [ |
||
164 | { |
||
165 | resource: 'http://email' |
||
166 | } |
||
167 | ], |
||
168 | phones: [ |
||
169 | { |
||
170 | resource: 'http://phone' |
||
171 | } |
||
172 | ], |
||
173 | addresses: [ |
||
174 | { |
||
175 | value: 'big long address', |
||
176 | postalCode: '123456' |
||
177 | } |
||
178 | ], |
||
179 | person: { |
||
180 | resource: 'http://person' |
||
181 | } |
||
182 | } |
||
183 | ], |
||
184 | events: [ |
||
185 | { |
||
186 | type: 'http://gedcomx.org/Marriage', |
||
187 | date: { |
||
188 | formal: '+2002-06-06' |
||
189 | }, |
||
190 | place: { |
||
191 | original: 'Her town, MN' |
||
192 | }, |
||
193 | roles: [ |
||
194 | { |
||
195 | person: { |
||
196 | resource: 'http://groom' |
||
197 | }, |
||
198 | type: 'http://gedcomx.org/Participant' |
||
199 | } |
||
200 | ] |
||
201 | } |
||
202 | ], |
||
203 | documents: [ |
||
204 | { |
||
205 | type: 'http://gedcomx.org/Abstract', |
||
206 | extracted: false, |
||
207 | textType: 'plain', |
||
208 | text: 'Lots of text', |
||
209 | attribution: { |
||
210 | created: 123456789 |
||
211 | } |
||
212 | } |
||
213 | ], |
||
214 | places: [ |
||
215 | { |
||
216 | names : [ |
||
217 | { |
||
218 | lang : 'en', |
||
219 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
220 | } |
||
221 | ], |
||
222 | type : 'http://identifier/for/the/place/type', |
||
223 | place : { resource : 'http://place' }, |
||
224 | jurisdiction : { resource : 'http://jurisdiction' }, |
||
225 | latitude : 27.9883575, |
||
226 | longitude : 86.9252014, |
||
227 | temporalDescription : { |
||
228 | formal: '+1899-01-04' |
||
229 | }, |
||
230 | spatialDescription : { |
||
231 | resource : 'http://uri/for/KML/document' |
||
232 | } |
||
233 | } |
||
234 | ] |
||
235 | }; |
||
236 | |||
237 | it('Create plain', function(){ |
||
238 | var newGedx = new GedcomX(), |
||
239 | gedx = GedcomX(); |
||
240 | assert.instanceOf(newGedx, GedcomX.Root, 'An instance of GedcomX is not returned when calling the constructor with new.'); |
||
241 | assert.instanceOf(gedx, GedcomX.Root, 'An instance of GedcomX is not returned when calling the constructor without new.'); |
||
242 | assert.jsonSchema(newGedx.toJSON(), GedcomXSchema); |
||
243 | assert.jsonSchema(gedx.toJSON(), GedcomXSchema); |
||
244 | }); |
||
245 | |||
246 | it('Create with JSON', function(){ |
||
247 | var gedx = GedcomX(fullJSON); |
||
248 | tests(gedx); |
||
249 | }); |
||
250 | |||
251 | it('Create with mixed data', function(){ |
||
252 | var gedx = GedcomX({ |
||
253 | id: 'gedcomx', |
||
254 | lang: 'en', |
||
255 | description: '#sd1', |
||
256 | attribution: GedcomX.Attribution({ |
||
257 | changeMessage: 'It changed', |
||
258 | contributor: GedcomX.ResourceReference({ resource: 'https://myapp.com/contributor'}), |
||
259 | created: new Date(1111338494969), |
||
260 | creator: GedcomX.ResourceReference({ resource: 'https://myapp.com/creator'}), |
||
261 | modified: new Date(1111338494969) |
||
262 | }), |
||
263 | persons: [ |
||
264 | GedcomX.Person({ |
||
265 | gender: { |
||
266 | type: 'http://gedcomx.org/Female' |
||
267 | }, |
||
268 | names: [ |
||
269 | { |
||
270 | type: 'http://gedcomx.org/BirthName', |
||
271 | nameForms: [ |
||
272 | { |
||
273 | fullText: 'Joanna Hopkins' |
||
274 | } |
||
275 | ] |
||
276 | } |
||
277 | ], |
||
278 | facts: [ |
||
279 | { |
||
280 | type: 'http://gedcomx.org/Birth', |
||
281 | date: { |
||
282 | formal: '+2001-04-09' |
||
283 | }, |
||
284 | place: { |
||
285 | original: 'Farm house' |
||
286 | } |
||
287 | } |
||
288 | ] |
||
289 | }) |
||
290 | ], |
||
291 | relationships: [ |
||
292 | GedcomX.Relationship({ |
||
293 | type: 'http://gedcomx.org/Couple', |
||
294 | person1: { |
||
295 | resource: 'http://identifier/for/person/1' |
||
296 | }, |
||
297 | person2: { |
||
298 | resource: 'http://identifier/for/person/2' |
||
299 | }, |
||
300 | facts: [ |
||
301 | GedcomX.Fact({ |
||
302 | type: 'http://gedcomx.org/Marriage' |
||
303 | }) |
||
304 | ] |
||
305 | }) |
||
306 | ], |
||
307 | sourceDescriptions: [ |
||
308 | GedcomX.SourceDescription({ |
||
309 | id: 'sd1', |
||
310 | resourceType: 'http://some/type', |
||
311 | citations: [ |
||
312 | GedcomX.SourceCitation({ |
||
313 | lang: 'en', |
||
314 | value: 'Long source citation' |
||
315 | }) |
||
316 | ], |
||
317 | mediaType: 'book', |
||
318 | about: 'http://a/resource', |
||
319 | mediator: { |
||
320 | resource: 'http://mediator' |
||
321 | }, |
||
322 | sources: [ |
||
323 | GedcomX.SourceReference({ |
||
324 | description: 'http://source/reference' |
||
325 | }) |
||
326 | ], |
||
327 | analysis: { |
||
328 | resource: 'http://analysis' |
||
329 | }, |
||
330 | componentOf: { |
||
331 | description: 'http://container' |
||
332 | }, |
||
333 | titles: [ |
||
334 | GedcomX.TextValue({ |
||
335 | lang: 'en', |
||
336 | value: 'Title' |
||
337 | }), |
||
338 | { |
||
339 | lang: 'es', |
||
340 | value: 'Titulo' |
||
341 | } |
||
342 | ], |
||
343 | notes: [ |
||
344 | GedcomX.Note({ |
||
345 | subject: 'Note', |
||
346 | text: 'Some note text' |
||
347 | }) |
||
348 | ], |
||
349 | attribution: { |
||
350 | created: 1234578129 |
||
351 | }, |
||
352 | rights: [ |
||
353 | GedcomX.ResourceReference({ |
||
354 | resource: 'https://some/right' |
||
355 | }) |
||
356 | ], |
||
357 | coverage: GedcomX.Coverage({ |
||
358 | temporal: { |
||
359 | formal: '+2015' |
||
360 | }, |
||
361 | spatial: { |
||
362 | original: 'A place' |
||
363 | } |
||
364 | }), |
||
365 | descriptions: [ |
||
366 | { |
||
367 | value: 'A description' |
||
368 | } |
||
369 | ], |
||
370 | identifiers: { |
||
371 | $: 'identifier' |
||
372 | }, |
||
373 | created: 1000000, |
||
374 | modified: 11111111, |
||
375 | repository: GedcomX.ResourceReference({ |
||
376 | resource: 'http://repository' |
||
377 | }) |
||
378 | }) |
||
379 | ], |
||
380 | agents: [ |
||
381 | GedcomX.Agent({ |
||
382 | id: 'agent', |
||
383 | identifiers: GedcomX.Identifiers({ |
||
384 | $: 'ident' |
||
385 | }), |
||
386 | names: [ |
||
387 | GedcomX.TextValue({ |
||
388 | lang: 'en', |
||
389 | value: 'Name' |
||
390 | }) |
||
391 | ], |
||
392 | homepage: GedcomX.ResourceReference({ |
||
393 | resource: 'http://homepage' |
||
394 | }), |
||
395 | openid: GedcomX.ResourceReference({ |
||
396 | resource: 'http://openid' |
||
397 | }), |
||
398 | accounts: [ |
||
399 | GedcomX.OnlineAccount({ |
||
400 | accountName: 'jimbo' |
||
401 | }) |
||
402 | ], |
||
403 | emails: [ |
||
404 | GedcomX.ResourceReference({ |
||
405 | resource: 'http://email' |
||
406 | }) |
||
407 | ], |
||
408 | phones: [ |
||
409 | GedcomX.ResourceReference({ |
||
410 | resource: 'http://phone' |
||
411 | }) |
||
412 | ], |
||
413 | addresses: [ |
||
414 | GedcomX.Address({ |
||
415 | value: 'big long address', |
||
416 | postalCode: '123456' |
||
417 | }) |
||
418 | ], |
||
419 | person: GedcomX.ResourceReference({ |
||
420 | resource: 'http://person' |
||
421 | }) |
||
422 | }) |
||
423 | ], |
||
424 | events: [ |
||
425 | GedcomX.Event({ |
||
426 | type: 'http://gedcomx.org/Marriage', |
||
427 | date: GedcomX.Date({ |
||
428 | formal: '+2002-06-06' |
||
429 | }), |
||
430 | place: GedcomX.PlaceReference({ |
||
431 | original: 'Her town, MN' |
||
432 | }), |
||
433 | roles: [ |
||
434 | GedcomX.EventRole({ |
||
435 | person: { |
||
436 | resource: 'http://groom' |
||
437 | }, |
||
438 | type: 'http://gedcomx.org/Participant' |
||
439 | }) |
||
440 | ] |
||
441 | }) |
||
442 | ], |
||
443 | documents: [ |
||
444 | GedcomX.Document({ |
||
445 | type: 'http://gedcomx.org/Abstract', |
||
446 | extracted: false, |
||
447 | textType: 'plain', |
||
448 | text: 'Lots of text', |
||
449 | attribution: GedcomX.Attribution({ |
||
450 | created: 123456789 |
||
451 | }) |
||
452 | }) |
||
453 | ], |
||
454 | places: [ |
||
455 | GedcomX.PlaceDescription({ |
||
456 | names : [ |
||
457 | GedcomX.TextValue({ |
||
458 | lang : 'en', |
||
459 | value : 'Pope\'s Creek, Westmoreland, Virginia, United States' |
||
460 | }) |
||
461 | ], |
||
462 | type : 'http://identifier/for/the/place/type', |
||
463 | place : GedcomX.ResourceReference({ resource : 'http://place' }), |
||
464 | jurisdiction : GedcomX.ResourceReference({ resource : 'http://jurisdiction' }), |
||
465 | latitude : 27.9883575, |
||
466 | longitude : 86.9252014, |
||
467 | temporalDescription : GedcomX.Date({ |
||
468 | formal: '+1899-01-04' |
||
469 | }), |
||
470 | spatialDescription : GedcomX.ResourceReference({ |
||
471 | resource : 'http://uri/for/KML/document' |
||
472 | }) |
||
473 | }) |
||
474 | ] |
||
475 | }); |
||
476 | |||
477 | tests(gedx); |
||
478 | }); |
||
479 | |||
480 | it('Build', function(){ |
||
481 | var gedx = GedcomX() |
||
482 | .setId('gedcomx') |
||
483 | .setLang('en') |
||
484 | .setDescription('#sd1') |
||
485 | .setAttribution(GedcomX.Attribution() |
||
486 | .setChangeMessage('It changed') |
||
487 | .setContributor({ resource: 'https://myapp.com/contributor'}) |
||
488 | .setCreated(1111338494969) |
||
489 | .setCreator({ resource: 'https://myapp.com/creator'}) |
||
490 | .setModified(1111338494969)) |
||
491 | .addPerson( |
||
492 | GedcomX.Person() |
||
493 | .setId('testPerson') |
||
494 | .setPrivate(true) |
||
495 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
||
496 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
||
497 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) |
||
498 | ) |
||
499 | .addRelationship( |
||
500 | GedcomX.Relationship() |
||
501 | .setType('http://gedcomx.org/Couple') |
||
502 | .setPerson1(GedcomX.ResourceReference().setResource('http://identifier/for/person/1')) |
||
503 | .setPerson2(GedcomX.ResourceReference().setResource('http://identifier/for/person/2')) |
||
504 | .addFact(GedcomX.Fact().setType('http://gedcomx.org/Marriage')) |
||
505 | ) |
||
506 | .addSourceDescription( |
||
507 | GedcomX.SourceDescription() |
||
508 | .setId('sd1') |
||
509 | .setResourceType('http://some/type') |
||
510 | .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
||
511 | .setMediaType('book') |
||
512 | .setAbout('http://a/resource') |
||
513 | .setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
||
514 | .addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
||
515 | .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
||
516 | .setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
||
517 | .addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
||
518 | .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
||
519 | .addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
||
520 | .setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
||
521 | .addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
||
522 | .setCoverage( |
||
523 | GedcomX.Coverage() |
||
524 | .setTemporal(GedcomX.Date().setFormal('+2015')) |
||
525 | .setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
||
526 | ) |
||
527 | .addDescription(GedcomX.TextValue().setValue('A description')) |
||
528 | .setIdentifiers(GedcomX.Identifiers({ |
||
529 | $: 'identifier' |
||
530 | })) |
||
531 | .setCreated(1000000) |
||
532 | .setModified(11111111) |
||
533 | .setRepository(GedcomX.ResourceReference().setResource('http://repository')) |
||
534 | ) |
||
535 | .addAgent( |
||
536 | GedcomX.Agent() |
||
537 | .setId('agent') |
||
538 | .setIdentifiers(GedcomX.Identifiers({$:'ident'})) |
||
539 | .addName(GedcomX.TextValue().setLang('en').setValue('Name')) |
||
540 | .setHomepage(GedcomX.ResourceReference().setResource('http://homepage')) |
||
541 | .setOpenid(GedcomX.ResourceReference().setResource('http://openid')) |
||
542 | .addAccount(GedcomX.OnlineAccount().setAccountName('jimbo')) |
||
543 | .addEmail(GedcomX.ResourceReference().setResource('http://email')) |
||
544 | .addPhone(GedcomX.ResourceReference().setResource('http://phone')) |
||
545 | .addAddress(GedcomX.Address().setValue('big long address').setPostalCode('123456')) |
||
546 | .setPerson(GedcomX.ResourceReference().setResource('http://person')) |
||
547 | ) |
||
548 | .addEvent( |
||
549 | GedcomX.Event() |
||
550 | .setType('http://gedcomx.org/Marriage') |
||
551 | .setDate(GedcomX.Date().setFormal('+2002-06-06')) |
||
552 | .setPlace(GedcomX.PlaceReference().setOriginal('Her town, MN')) |
||
553 | .addRole(GedcomX.EventRole() |
||
554 | .setType('http://gedcomx.org/Participant') |
||
555 | .setPerson(GedcomX.ResourceReference().setResource('http://groom'))) |
||
556 | ) |
||
557 | .addDocument( |
||
558 | GedcomX.Document() |
||
559 | .setType('http://gedcomx.org/Abstract') |
||
560 | .setExtracted(false) |
||
561 | .setTextType('plain') |
||
562 | .setText('Lots of text') |
||
563 | .setAttribution(GedcomX.Attribution().setCreated(123456789)) |
||
564 | ) |
||
565 | .addPlace( |
||
566 | GedcomX.PlaceDescription() |
||
567 | .addName(GedcomX.TextValue().setLang('en').setValue('Pope\'s Creek, Westmoreland, Virginia, United States')) |
||
568 | .setType('http://identifier/for/the/place/type') |
||
569 | .setPlace(GedcomX.ResourceReference({ resource : 'http://place' })) |
||
570 | .setJurisdiction(GedcomX.ResourceReference({ resource : 'http://jurisdiction' })) |
||
571 | .setLatitude(27.9883575) |
||
572 | .setLongitude(86.9252014) |
||
573 | .setTemporalDescription(GedcomX.Date({ |
||
574 | formal: '+1899-01-04' |
||
575 | })) |
||
576 | .setSpatialDescription(GedcomX.ResourceReference({ |
||
577 | resource : 'http://uri/for/KML/document' |
||
578 | })) |
||
579 | ); |
||
580 | |||
581 | tests(gedx); |
||
582 | }); |
||
583 | |||
584 | it('toJSON', function(){ |
||
585 | var gedx = GedcomX(fullJSON); |
||
586 | assert.deepEqual(gedx.toJSON(), fullJSON); |
||
587 | assert.jsonSchema(gedx.toJSON(), GedcomXSchema); |
||
588 | }); |
||
589 | |||
590 | it('constructor does not copy instances', function(){ |
||
591 | var obj1 = GedcomX(); |
||
592 | var obj2 = GedcomX(obj1); |
||
593 | assert.strictEqual(obj1, obj2); |
||
594 | }); |
||
595 | |||
596 | }); |
||
597 | |||
709 | } |